﻿@using QDT.Core
@using QDT.Core.OfflineInvest
@model QDT.Core.Members.User
@{
    ViewBag.Title = "线下设置";
    var contracts = ViewData["UserContract"] as ICollection<OfflineContract>;
}

@section Head{
    <script type="text/javascript">
        $().ready(function() {
            $('#submit_newContract').click(function () {
                addNewContract();
            });
        });

        function addNewContract() {
            var money = $('[name="Money"]').val();
            var startDate = $('[name="StartDate"]').val();
            var endDate = $('[name="EndDate"]').val();
            var safePassword = $('[name="SafePassword"]').val();

            data.Money = money;
            data.StartDate = startDate;
            data.EndDate = endDate;
            data.SafePassword = safePassword;

            var url = '@Url.Action("NewContract")';
            $.ajax({
                url: url,
                data: data,
                type: 'POST',
                dataType: "json",
                success: function (obj) {
                    alert(obj.Info);
                    if (obj.Status == true)
                        location.href = location.href;
                }
            });
        }

        function advance(id) {

            if (!confirm("确定要提前中止合同？")) {
                window.event.returnValue = false;
                return;
            }

            var url = '@Url.Action("AdvanceCarry")' + '?id=' + id;
            $.ajax({
                url: url,
                type: 'get',
                dataType: "json",
                success: function (obj) {
                    alert(obj.Info);
                    if (obj.Status == true) location.href = location.href;
                }
            });
        }

    </script>
}

<div class="ui-body">
    <div class="ui-inner">
        <div class="ui-grid-row">

            @Html.Action("UserMenu", new {route = MenuRoute.OfflineSet})

            <div class="ui-grid-20">
                <div class="ui-box ui-bank-list fn-clear">
                    <div style="float: left; width: 365px;">
                    
                        @foreach (var c in contracts)
                        {
                            <div class="ui-inbox">
                            <div class="ui-inbox-head">
                                <h3 class="ui-inbox-head-title">合同编号 : 000<span>@c.ID</span></h3>
                                @if (c.Status == 0)
                                {
                                    <div class="ui-inbox-head-more">生效<a style="color: #c0c0c0;" href="javascript:void(0);" onclick="advance(@c.ID)">（中止合同）</a></div>
                                }
                                @if (c.Status == 1)
                                {
                                    <div class="ui-inbox-head-more" style="color: #e74c3c;">已提交申请</div>
                                }
                                @if (c.Status == 3 || c.Status == 2)
                                {
                                    <div class="ui-inbox-head-more" style="color: #e74c3c;">申请通过</div>
                                }
                                @if (c.Status == 4)
                                {
                                    <div class="ui-inbox-head-more" style="color: #e74c3c;">已结束</div>
                                }
                                @if (c.Status == -2)
                                 {
                                    <div class="ui-inbox-head-more" style="color: #e74c3c;">申请已驳回</div>
                                 }
                                 @if (c.Status == -1)
                                 {
                                    <div class="ui-inbox-head-more" style="color: #e74c3c;">等待审核</div>
                                 }
                            </div>
                            <div class="ui-inbox-container">
                                <div class="ui-inbox-content">
                                    <p>投资金额：@c.Money.ToMoney()</p>
                                    <p>已赚收益：@c.RepayEarning.ToMoney()</p>
                                    <p>投资区间：@c.StartDate.ToString("yyyy-MM-dd") -- @c.EndDate.ToString("yyyy-MM-dd")</p>
                                </div>
                            </div>
                        </div>
                        }

                    </div>

                    <div class="ui-inbox">
                        <div class="ui-inbox-head">
                            <h3 class="ui-inbox-head-title"><i class="iconfont">&#xf0154;</i> 线下投资合同</h3>
                        </div>
                        <div class="ui-inbox-container">
                            <div class="ui-inbox-content">
                                <form class="ui-form ui-form-mini" method="post" action="@Url.Action("NewContract")" >
                                    <fieldset>
                                        <div class="ui-form-item">
                                            <label for="" class="ui-label">
                                                投资金额
                                            </label>
                                            <input type="text" name="Money" class="ui-input" style="width: 180px"/>
                                        </div>
                                        
                                        <div class="ui-form-item">
                                            <label for="" class="ui-label">
                                                开始时间
                                            </label>
                                            <input type="text" name="StartDate" class="ui-input" style="width: 180px" value="@DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")" readonly="readonly"/>
                                        </div>
                                        
                                        <div class="ui-form-item">
                                            <label for="" class="ui-label">
                                                投资期限
                                            </label>
                                            <select name="EndDate" style="width: 200px; height: 34px;">
                                                <option value="3">三个月</option>
                                                <option value="6">六个月</option>
                                                <option value="9">九个月</option>
                                                <option value="12" selected="selected">十二个月</option>
                                                <option value="18">十八个月</option>
                                                <option value="24">二十四个月</option>
                                            </select>
                                        </div>
                                        
                                        <div class="ui-form-item">
                                            <label for="" class="ui-label">
                                                安全密码
                                            </label>
                                            <input type="password" name="SafePassword" class="ui-input" style="width: 180px"/>
                                        </div>

                                        <div class="ui-form-item">
                                            @if (Model.IDCardPassed)
                                            {
                                                <input type="submit"  class="ui-button ui-button-orange"  value="添加"/>
                                            }
                                            else
                                            {
                                                <a type="submit" href="@Url.Action("BindIdCard")" class="ui-button ui-button-orange">实名认证</a>
                                            }
                                        </div>

                                    </fieldset>
                                </form>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </div>
    </div>
</div>

